package com.itheima.dubbo.impl;

import com.itheima.dubbo.UserFace;
import com.itheima.dubbo.pojo.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.config.annotation.Method;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;

/**
 * @Description:
 * @Version: V1.0
 */
//@DubboService(timeout = 2000)   // 服务注册注解
//@DubboService(retries=0)  // 重试次数，默认是2次
//@DubboService(timeout=5000,
//        methods = {
//        @Method(name = "hello", retries = 0, timeout = 2000),
//        @Method(name = "findByUser", retries = 2)
//})  // 为某个方法添加配置, 结论：服务提供方：Method 》 DubboService
//@DubboService(version = "1.0.0")
@DubboService(cluster = "failfast")
public class UserFaceImpl implements UserFace {

    @Autowired
    private  Environment environment;

    /**
     * hello 用户
     * @param username
     * @return
     */
    @Override
    public String hello(String username) {
        int i = 1 / 0;
        System.out.println("UserFaceImpl hello...."
                + environment.getProperty("server.port"));


//        try {
//            Thread.sleep(4000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }


        return "Hello Dubbo username=" + username;
    }

    @Override
    public User findByUser(User user) {
        return user;
    }
}
